//
//  MCAccountApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/26.
//

import Foundation
import Moya

enum MCAccountApi {
    case bingWx(authCode:String)
    case logOff
    case logOut
}

extension MCAccountApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .bingWx:
            return "api/app/setting/bindWx"
        case .logOff:
            return "api/app/setting/logoff"
        case .logOut:
            return "api/app/setting/logout"
        }
    }
    var method:Moya.Method {
        switch self {
        case .bingWx,.logOff,.logOut:
            return .post
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .bingWx(authCode):
            return .requestParameters(parameters: ["authCode":authCode], encoding: URLEncoding.default)
        case .logOff:
            return .requestPlain
        case .logOut:
            return .requestPlain
        }
    }
    
    var headers: [String : String]? {
        
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        
        switch self {
        case .bingWx,.logOff,.logOut:
            return [tokenName:tokenValue]
        }
        
        
    }
    
    
}
